package com.yami.trading.api.controller;
import com.yami.trading.bean.item.domain.Item;
import com.yami.trading.bean.item.domain.ItemSummary;
import com.yami.trading.common.domain.Result;
import javax.validation.Valid;
import com.google.common.collect.Lists;
import com.yami.trading.common.lang.LangUtils;
import com.yami.trading.common.query.QueryWrapperGenerator;

import com.yami.trading.service.item.ItemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.yami.trading.bean.item.dto.ItemSummaryDTO;
import com.yami.trading.bean.item.mapstruct.ItemSummaryWrapper;
import com.yami.trading.service.item.ItemSummaryService;
import com.yami.trading.bean.item.query.ItemSummaryQuery;




/**
 * 简况Controller
 * @author lucas
 * @version 2023-05-01
 */

@Api(tags ="h5简况")
@RestController
@RequestMapping(value = "api/item/itemSummary")
public class ItemSummaryController {

	@Autowired
	private ItemSummaryService itemSummaryService;

	@Autowired
	private ItemSummaryWrapper itemSummaryWrapper;
	@Autowired
	private ItemService itemService;
	/*
	 * 根据Id获取简况数据
	 */
	@ApiOperation(value = "根据symbol获取简况数据")
	@GetMapping("get")
	public Result<ItemSummary> queryById(@RequestParam String symbol) {
		Item bySymbol = itemService.findBySymbol(symbol);
		if(bySymbol == null){
			return Result.failed ("币对不存在");
		}
		ItemSummary orNewOne = itemSummaryService.getOrNewOne(symbol);
		orNewOne.setSymbolName(bySymbol.getName());
		if(LangUtils.isEnItem()){
			bySymbol.transName();
			ItemSummary en = itemSummaryService.getOneByLang(symbol, "en");
			if(en == null){
				return Result.ok (orNewOne);
			}
			en.setSymbolName(bySymbol.getName());
			return Result.ok (en);
		}
		return Result.ok (orNewOne);
	}


}
